package com.xcf.controller.business.consignhandle;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xcf.controller.base.BaseController;
import com.xcf.controller.base.ExportDataHandler;
import com.xcf.entity.Page;
import com.xcf.service.business.bookingcargo.BookingCargoService;
import com.xcf.service.business.bookingcargo.BookingNoteService;
import com.xcf.service.business.consign.CostModifyService;
import com.xcf.service.business.settlement.AccountAdjustmentService;
import com.xcf.service.system.user.impl.UserService;
import com.xcf.util.DateUtil;
import com.xcf.util.Jurisdiction;
import com.xcf.util.PageData;
import com.xcf.util.ResponseResult;

import cn.com.xcf.dao.model.FactBookingNote;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@RequestMapping(value = "/consignHandle")
public class ConsignHandleController extends BaseController implements ExportDataHandler{

	@Autowired
	private BookingCargoService bookingCargoService;
	@Autowired
	private BookingNoteService bookingNoteService;
	@Autowired
	private AccountAdjustmentService accountAdjustmentService;
	@Autowired
	private UserService userService;
	@Autowired
	private CostModifyService costModifyService;
	//点击保存按钮
	@RequestMapping(value="list")
	@ResponseBody
	public ResponseResult list(int page){
		PageData pd = new PageData();
		pd=this.getPageData();
		PageHelper.startPage(page, 25);
		List<Map> list = bookingCargoService.queryByPage(pd);
		List<Map>list1=new ArrayList<>();
		for (Map map : list) {
			if(map.get("ISSET_ABOUT")!=null&&map.get("ISSET_ABOUT").equals(true)){
				map.put("ISSET_ABOUT", "是");
				
			}else{
				map.put("ISSET_ABOUT", "否");
			}
			if(map.get("ENTRUST_TIME")!=null&&map.get("ENTRUST_TIME")!=""){
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				String ENTRUST_TIME = sdf.format(map.get("ENTRUST_TIME"));
				map.put("ENTRUST_TIME",ENTRUST_TIME );//接受委托时间
			}else{
				map.put("ENTRUST_TIME",map.get("ENTRUST_TIME") );//接受委托时间
			}
			list1.add(map);
		}
		return ResponseResult.success(new PageInfo(list));
	}

		@RequestMapping(value="listByBillCode")
		@ResponseBody
		public ResponseResult listByBillCode(int page){
			PageHelper.startPage(page, 35);
			PageData pd = new PageData();
			pd = this.getPageData();
			Map<String, Object>params = new HashMap<String, Object>();
			params.put("BILL_CODE", pd.getString("billCode"));
			params.put("LADING_BILL_CODE", pd.getString("ladingBillCode"));
			
			List<Map> list = bookingCargoService.findFee(params);
			return ResponseResult.success(new PageInfo(list));
		}

				@RequestMapping(value="copeListByBillCode")
				@ResponseBody
				public ResponseResult copeListByBillCode(int page){
					PageHelper.startPage(page, 35);
					PageData pd = new PageData();
					pd = this.getPageData();
					Map<String, Object>params = new HashMap<String, Object>();
					params.put("BILL_CODE", pd.getString("billCode"));
					params.put("LADING_BILL_CODE", pd.getString("ladingBillCode"));
					List<Map> list = bookingCargoService.findCopeFee(params);
					return ResponseResult.success(new PageInfo(list));
				}
				/**
				 * 比率
				 * @param response
				 * @throws Exception
				 */
				@RequestMapping(value="/findRate")
				public void findRate(HttpServletResponse response)throws Exception{
					PageData pd = new PageData();
					pd= this.getPageData();

					List<Map> list = bookingNoteService.findRate(pd);
					JSONArray json = new JSONArray();
					json.add(list);
					String tt = json.toString().substring(0, json.toString().length()-1);
					String yy = tt.substring(1, tt.length());
					response.setContentType("text/html; charset=utf-8");
					response.getWriter().write("{"+"\""+"rate"+"\""+":"+yy+"}");				
					response.getWriter().flush();
				}
				//箱主的下拉
				@RequestMapping(value="findInfo")
				public void findInfo(HttpServletResponse response) throws IOException{
					PageData pd = new PageData();
					pd= this.getPageData();
					List<PageData> list =bookingNoteService.finXiangzhu(pd);
					JSONArray arry = new JSONArray();
					for (PageData data : list) {
						JSONObject ob = new JSONObject();						
						ob.put("OWNER_CODE", data.getString("OWNER_CODE"));
						arry.add(ob);
					}
					response.setContentType("text/html; charset=utf-8");         
				     response.getWriter().write("{"+"\""+"totaltt"+"\""+":"+"\""+"10"+"\""+","+"\""+"rowsaa"+"\""+":"+arry+"}");
				}
			
				/**
				 * 拖车数据
				 * @param response
				 * @throws Exception
				 */
				@RequestMapping(value="/findTrailerByBillCode")
				@ResponseBody
				public ResponseResult findTrailerByBillCode()throws Exception{
					PageData pd = new PageData();
					pd= this.getPageData();

					List<Map> list = bookingNoteService.findTrailer(pd);
					return ResponseResult.success(new PageInfo(list));
//					JSONArray json = new JSONArray();
//					json.add(list);
//					String tt = json.toString().substring(0, json.toString().length()-1);
//					String yy = tt.substring(1, tt.length());
//					response.setContentType("text/html; charset=utf-8");
//					response.getWriter().write("{"+"\""+"trailer"+"\""+":"+yy+"}");				
//					response.getWriter().flush();
				}
				/**
				 * 拖车数据
				 * @param response
				 * @throws Exception
				 */
				@RequestMapping(value="/findTrailerByBillCodeTWO")
				@ResponseBody
				public ResponseResult findTrailerByBillCodeTWO()throws Exception{
					PageData pd = new PageData();
					pd= this.getPageData();

					List<Map> list = bookingNoteService.findTrailer(pd);
//					JSONArray json = new JSONArray();
//					json.add(list);
//					String tt = json.toString().substring(0, json.toString().length()-1);
//					String yy = tt.substring(1, tt.length());
//					response.setContentType("text/html; charset=utf-8");
//					response.getWriter().write("{"+"\""+"trailerTwo"+"\""+":"+yy+"}");				
//					response.getWriter().flush();
					return ResponseResult.success(new PageInfo(list));
				}
				/**
				 * 报关方式数据
				 * @param response
				 * @throws Exception
				 */
				@RequestMapping(value="/findCustomsMode")
				public void findCustomsMode(HttpServletResponse response)throws Exception{
					PageData pd = new PageData();
					pd= this.getPageData();

					List<Map> list = bookingNoteService.findCustomsMode(pd);
					JSONArray json = new JSONArray();
					json.add(list);
					String tt = json.toString().substring(0, json.toString().length()-1);
					String yy = tt.substring(1, tt.length());
					response.setContentType("text/html; charset=utf-8");
					response.getWriter().write("{"+"\""+"customsMode"+"\""+":"+yy+"}");				
					response.getWriter().flush();
				}
				/**
				 * 报关行数据
				 * @param response
				 * @throws Exception
				 */
				@RequestMapping(value="/findCustoms")
				public void findCustoms(HttpServletResponse response)throws Exception{
					PageData pd = new PageData();
					pd= this.getPageData();

					List<Map> list = bookingNoteService.findCustoms(pd);
					JSONArray json = new JSONArray();
					json.add(list);
					String tt = json.toString().substring(0, json.toString().length()-1);
					String yy = tt.substring(1, tt.length());
					response.setContentType("text/html; charset=utf-8");
					response.getWriter().write("{"+"\""+"customs"+"\""+":"+yy+"}");				
					response.getWriter().flush();
				}
				/**
				 * 提单类型数据
				 * @param response
				 * @throws Exception
				 */
				@RequestMapping(value="/findBillType")
				public void findBillType(HttpServletResponse response)throws Exception{
					PageData pd = new PageData();
					pd= this.getPageData();

					List<Map> list = bookingNoteService.findBillType(pd);
					JSONArray json = new JSONArray();
					json.add(list);
					String tt = json.toString().substring(0, json.toString().length()-1);
					String yy = tt.substring(1, tt.length());
					response.setContentType("text/html; charset=utf-8");
					response.getWriter().write("{"+"\""+"billType"+"\""+":"+yy+"}");				
					response.getWriter().flush();
				}
				/**
				 * 保存或更新拖车数据
				 * @return
				 * @throws Exception
				 */
				@RequestMapping(value="/saveOrUpdate")
				@ResponseBody
				public String saveOrUpdate()throws Exception{
					PageData pd = new PageData();
					pd= this.getPageData();
					if(pd.getString("ID")==null || pd.getString("ID")==""){
						bookingNoteService.saveTrailer(pd);
					}else{
						int TRAILER_TYPE= 0;
						if(pd.getString("TRAILER_TYPE") .equals("起运港拖车")){
							TRAILER_TYPE =1;
		        		}else{
		        			TRAILER_TYPE=0;
		        		}
						int PACKING_TYPE= 0;
		        		if(pd.getString("PACKING_TYPE").equals("装箱")){
		        			PACKING_TYPE =0;
		        		}else{
		        			PACKING_TYPE=1;
		        		}
		        		pd.put("TRAILER_TYPE", TRAILER_TYPE);
		        		pd.put("PACKING_TYPE", PACKING_TYPE);
						bookingNoteService.updateTrailer(pd);
					}
					return null;
					
				}
				
				/**
				 * 删除拖车信息
				 * @return
				 * @throws Exception
				 */
				@RequestMapping(value="/deleteTrailer")
				@ResponseBody
				public String deleteTrailer()throws Exception{
					PageData pd = new PageData();
					pd = this.getPageData();

					String data = pd.getString("array");

					JSONArray items = JSONArray.fromObject(data);
					for(int i=0,size=items.size();i<size;i++){
						JSONObject item = items.getJSONObject(i);
						String id = item.getString("id").trim();
						PageData pdq = new PageData();
						pdq.put("ID", id);
						bookingNoteService.deleteTrailer(pdq);
					}
					return null;
					
				}/**
				 * 更新托单信息
				 * @return
				 * @throws Exception
				 */
				@RequestMapping(value="/updateBookNote")
				@ResponseBody
				public String updateBookNote()throws Exception{
					PageData pd = new PageData();
					pd= this.getPageData();
					bookingNoteService.updateBookNoteInfo(pd);
					return null;
					
				}
	/**
	 * 往前端传值
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/findRiverShipCompany")
	public void findRiverShipCompanyInfo(HttpServletResponse response)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();

		List<Map> list = bookingCargoService.findRiverShipCompany(null);
		JSONArray json = new JSONArray();
		json.add(list);
		String tt = json.toString().substring(0, json.toString().length()-1);
		String yy = tt.substring(1, tt.length());
		response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"tt"+"\""+":"+yy+"}");				
		response.getWriter().flush();
	}
	/**
	 * 费用名称数据
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/findFeeNameInfo")
	public void findFeeNameInfo(HttpServletResponse response)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		Map<String, Object>params = new HashMap<String, Object>();
		List<Map> list = bookingCargoService.findFeeName(params);
		JSONArray json = new JSONArray();
		json.add(list);
		String tt = json.toString().substring(0, json.toString().length()-1);
		String yy = tt.substring(1, tt.length());
		response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"root"+"\""+":"+yy+"}");				
		response.getWriter().flush();
	}
	
	/**
	 * 结算单位数据
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/findSettlement")
	public void findSettlement(HttpServletResponse response)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		Map<String, Object>params = new HashMap<String, Object>();
		List<Map> list = bookingCargoService.findSettlement(params);
		JSONArray json = new JSONArray();
		json.add(list);
		String tt = json.toString().substring(0, json.toString().length()-1);
		String yy = tt.substring(1, tt.length());
		response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"settlement"+"\""+":"+yy+"}");				
		response.getWriter().flush();
	}
	/**
	 * @author zhouheyou
	 * @throws IOException 
	 * 
	 * 
	 */
	@RequestMapping(value="/findjiesuan")
	public void findjiesuan(HttpServletResponse response) throws IOException{
		PageData pd = new PageData();
		pd = this.getPageData();
		List<PageData> list = bookingCargoService.findjiesuan(pd);
		JSONArray arry = new JSONArray();
		for (PageData data : list) {
			JSONObject ob = new JSONObject();
			ob.put("ID", data.get("ID"));
			ob.put("ENTITIES_FULLNAME", data.getString("ENTITIES_FULLNAME"));
			arry.add(ob);
		}
		response.setContentType("text/html; charset=utf-8");         
	     response.getWriter().write("{"+"\""+"total520"+"\""+":"+"\""+"10"+"\""+","+"\""+"rows520"+"\""+":"+arry+"}");
	 
	}
	
	/**
	 * 箱型管理数据
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/findboxType")
	public void findboxType(HttpServletResponse response)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		Map<String, Object>params = new HashMap<String, Object>();
		List<Map> list = bookingCargoService.findBoxtype(params);
		JSONArray json = new JSONArray();
		json.add(list);
		String tt = json.toString().substring(0, json.toString().length()-1);
		String yy = tt.substring(1, tt.length());
		response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"boxType"+"\""+":"+yy+"}");				
		response.getWriter().flush();
	}
	/**
	 * 查找价格
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/findAmount")
	@ResponseBody
	public String findAmount(HttpServletResponse response)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		String costName= pd.getString("COST_NAME");
		//判断业务编号是否为空
		if(pd.getString("BILL_CODE")==null){
			
		}
		else if(!pd.getString("BILL_CODE").isEmpty()){
			pd = accountAdjustmentService.findBookNoteByBillCode(pd);
			//判断业务类型是否为空
			if(!pd.getString("BUSINESS_TYPE_ID").isEmpty()){
				//通过业务类型判断内贸还是外贸查找不同表取出金额(业务类型ID是1或者2就是外贸，其余内贸)
				String fee = null;
				if(pd.get("BUSINESS_TYPE_ID").equals("1") || pd.get("BUSINESS_TYPE_ID").equals("2")){
					
					PageData cca =  accountAdjustmentService.findCCACostInfo(costName);
					PageData fix = accountAdjustmentService.findFixedFee(costName);
					if(cca!=null){
						fee = cca.get("UNIT_PRICE").toString();
					}else if(fix!=null){
						fee = fix.get("FEE_PRICE").toString();
					}else{  
						fee = "";
					}
				}else{
					PageData trade = accountAdjustmentService.findTradFee(costName);
					fee = trade.get("UNIT_PRICE").toString();
					
				}
				JSONObject jo = new JSONObject();
				JSONArray json = new JSONArray();
				jo.put("Fee", fee);
				json.add(jo);
				response.setContentType("text/html; charset=utf-8");
				response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"amount"+"\""+":"+json.toString()+"}");				
				response.getWriter().flush();
				
			}
		}
		return null;
		
	}
	/**
	 * 保存收款费用信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/saveFeeInfo")
	@ResponseBody
	public String saveFeeInfo()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		PageData pdq = this.getPageData();
		if(pd.getString("IS_INNER_SETTLEMENT").equals("1")){
			pdq.put("TAX_PRICE", Float.parseFloat(pdq.getString("TAX_PRICE"))*-1);
			pd.put("TAX_PRICE","0");
			
		}
		
		if(!pd.getString("TAX_PRICE").isEmpty()&&!pd.getString("EXCHANGE_RATE").isEmpty()&&!pd.getString("CONTAINER_NUM").isEmpty()){
//			pd.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
			if(pd.getString("CURRENCY").equals("RMB")){
				pd.put("EQUIVALENT_RMB", Float.parseFloat(pd.getString("TAX_PRICE"))*Integer.parseInt(pd.getString("CONTAINER_NUM")));
			}else if (pd.getString("CURRENCY").equals("USD")){
				pd.put("EQUIVALENT_RMB", Float.parseFloat(pd.get("TAX_PRICE").toString())*Integer.parseInt(pd.getString("CONTAINER_NUM"))/Float.parseFloat(pd.get("EXCHANGE_RATE").toString()));
			}
			
		}
		
		bookingCargoService.saveFeeInfo(pd);
		
		pdq.put("SETTLEMENT_UNIT", "");
		if(!pd.getString("TAX_PRICE").isEmpty()&&!pdq.getString("EXCHANGE_RATE").isEmpty()&&!pdq.getString("CONTAINER_NUM").isEmpty()){
//			pdq.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
			if(pdq.getString("CURRENCY").equals("RMB")){
				pdq.put("EQUIVALENT_RMB", Float.parseFloat(pdq.get("TAX_PRICE").toString())*Integer.parseInt(pdq.getString("CONTAINER_NUM")));
			}else if (pdq.getString("CURRENCY").equals("USD")){
				pdq.put("EQUIVALENT_RMB", Float.parseFloat(pdq.get("TAX_PRICE").toString())*Integer.parseInt(pdq.getString("CONTAINER_NUM"))/Float.parseFloat(pdq.get("EXCHANGE_RATE").toString()));
			}
			
		}
		bookingCargoService.saveFeeCopeInfo(pdq);
		return null;
		
	}
	/**
	 * 修改收款费用信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/updateFeeInfo")
	@ResponseBody
	public String updateFeeInfo()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();

//		
//		if(!pd.getString("TAX_PRICE").isEmpty()){
//			pd.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
//		}
		if(!pd.getString("TAX_PRICE").isEmpty()&&!pd.getString("EXCHANGE_RATE").isEmpty()&&!pd.getString("CONTAINER_NUM").isEmpty()){
//			pd.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
			if(pd.getString("CURRENCY").equals("RMB")){
				pd.put("EQUIVALENT_RMB", Float.parseFloat(pd.getString("TAX_PRICE"))*Integer.parseInt(pd.getString("CONTAINER_NUM")));
			}else if (pd.getString("CURRENCY").equals("USD")){
				pd.put("EQUIVALENT_RMB", Float.parseFloat(pd.get("TAX_PRICE").toString())*Integer.parseInt(pd.getString("CONTAINER_NUM"))/Float.parseFloat(pd.get("EXCHANGE_RATE").toString()));
			}
			
		}
		bookingCargoService.updateFeeInfo(pd);
		bookingCargoService.updateCopeFeeInfo(pd);
//		PageData pdq = this.getPageData();
//		pdq.put("SETTLEMENT_UNIT", "");
//		bookingCargoService.saveFeeCopeInfo(pdq);
		return null;
		
	}
	/**
	 * 保存付款款费用信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/saveFeeCopeInfo")
	@ResponseBody
	public String saveFeeCopeInfo()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		PageData pdq = this.getPageData();
		if(pd.getString("IS_INNER_SETTLEMENT").equals("1")){
			pdq.put("TAX_PRICE", Float.parseFloat(pdq.getString("TAX_PRICE"))*-1);
			pd.put("TAX_PRICE","0");
			
		}
		
//		if(!pd.getString("TAX_PRICE").isEmpty()){
//			pd.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
//		}
		if(!pd.getString("TAX_PRICE").isEmpty()&&!pd.getString("EXCHANGE_RATE").isEmpty()&&!pd.getString("CONTAINER_NUM").isEmpty()){
//			pd.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
			if(pd.getString("CURRENCY").equals("RMB")){
				pd.put("EQUIVALENT_RMB", Float.parseFloat(pd.getString("TAX_PRICE"))*Integer.parseInt(pd.getString("CONTAINER_NUM")));
			}else if (pd.getString("CURRENCY").equals("USD")){
				pd.put("EQUIVALENT_RMB", Float.parseFloat(pd.get("TAX_PRICE").toString())*Integer.parseInt(pd.getString("CONTAINER_NUM"))/Float.parseFloat(pd.get("EXCHANGE_RATE").toString()));
			}
			
		}
		bookingCargoService.saveFeeCopeInfo(pd);
		
	
		PageData pdqd = new PageData();
		String costName= URLDecoder.decode(pd.getString("COST_NAME"), "utf-8");
//		String fee = null;
		//判断业务编号是否为空
//		if(!pdq.getString("BILL_CODE").isEmpty()){
//			pdqd = accountAdjustmentService.findBookNoteByBillCode(pdq);
//			//判断业务类型是否为空
//			if(!pdqd.getString("BUSINESS_TYPE_ID").isEmpty()){
//				//通过业务类型判断内贸还是外贸查找不同表取出金额(业务类型ID是1或者2就是外贸，其余内贸)
//				
//				if(pdqd.get("BUSINESS_TYPE_ID").equals("1") || pdqd.get("BUSINESS_TYPE_ID").equals("2")){
//					
//					PageData cca =  accountAdjustmentService.findCCACostInfo(costName);
//					PageData fix = accountAdjustmentService.findFixedFee(costName);
//					if(cca!=null){
//						fee = cca.get("UNIT_PRICE").toString();
//					}else if(fix!=null){
//						fee = fix.get("FEE_PRICE").toString();
//					}else{  
//						fee = "";
//					}
//				}else{
//					PageData trade = accountAdjustmentService.findTradFee(costName);
//					fee = trade.get("UNIT_PRICE").toString();
//					
//				}
//				
//				
//			}
//		}
//		if(!fee.isEmpty()){
//			pdq.put("TAX_PRICE", Float.parseFloat(fee));
//		}
		if(!pd.getString("TAX_PRICE").isEmpty()&&!pdq.getString("EXCHANGE_RATE").isEmpty()&&!pdq.getString("CONTAINER_NUM").isEmpty()){
//			pdq.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
			if(pdq.getString("CURRENCY").equals("RMB")){
				pdq.put("EQUIVALENT_RMB", Float.parseFloat(pdq.get("TAX_PRICE").toString())*Integer.parseInt(pdq.getString("CONTAINER_NUM")));
			}else if (pdq.getString("CURRENCY").equals("USD")){
				pdq.put("EQUIVALENT_RMB", Float.parseFloat(pdq.get("TAX_PRICE").toString())*Integer.parseInt(pdq.getString("CONTAINER_NUM"))/Float.parseFloat(pdq.get("EXCHANGE_RATE").toString()));
			}
			
		}
//			pdq.put("SETTLEMENT_UNIT",URLDecoder.decode(pd.getString("shipperName"), "utf-8"));

		
		bookingCargoService.saveFeeInfo(pdq);
		return null;
	}
		/**
		 * 修改付款费用信息
		 * @return
		 * @throws Exception
		 */
		@RequestMapping(value="/updateCopeInfo")
		@ResponseBody
		public String updateCopeInfo()throws Exception{
			PageData pd = new PageData();
			pd = this.getPageData();

			
//			if(!pd.getString("TAX_PRICE").isEmpty()){
//				pd.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
//			}
			if(!pd.getString("TAX_PRICE").isEmpty()&&!pd.getString("EXCHANGE_RATE").isEmpty()&&!pd.getString("CONTAINER_NUM").isEmpty()){
//				pd.put("TAX_PRICE", Float.parseFloat(pd.getString("TAX_PRICE")));
				if(pd.getString("CURRENCY").equals("RMB")){
					pd.put("EQUIVALENT_RMB", Float.parseFloat(pd.getString("TAX_PRICE"))*Integer.parseInt(pd.getString("CONTAINER_NUM")));
				}else if (pd.getString("CURRENCY").equals("USD")){
					pd.put("EQUIVALENT_RMB", Float.parseFloat(pd.get("TAX_PRICE").toString())*Integer.parseInt(pd.getString("CONTAINER_NUM"))/Float.parseFloat(pd.get("EXCHANGE_RATE").toString()));
				}
				
			}
			bookingCargoService.updateCopeFeeInfo(pd);
			bookingCargoService.updateFeeInfo(pd);
//			PageData pdq = this.getPageData();
//			pdq.put("SETTLEMENT_UNIT", "");
//			bookingCargoService.saveFeeCopeInfo(pdq);
			return null;
			
		}

	 /**
	  * 删除信息
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping(value="/deleteFee")
	 @ResponseBody
	 public String deleteFee()throws Exception{
			PageData pd = new PageData();
			pd = this.getPageData();

			String data = pd.getString("array");

			JSONArray items = JSONArray.fromObject(data);
			for(int i=0,size=items.size();i<size;i++){
				JSONObject item = items.getJSONObject(i);
				String id = item.getString("ID").trim();
				PageData pdq = new PageData();
				pdq.put("ID", id);
				bookingCargoService.deleteFee(pdq);
			}
		return null;
		 
	 }
	 /**
	  * 删除信息
	  * @return
	  * @throws Exception
	  */
	 @RequestMapping(value="/deleteCopeFee")
	 @ResponseBody
	 public String deleteCopeFee()throws Exception{
			PageData pd = new PageData();
			pd = this.getPageData();

			String data = pd.getString("array");

			JSONArray items = JSONArray.fromObject(data);
			for(int i=0,size=items.size();i<size;i++){
				JSONObject item = items.getJSONObject(i);
				String id = item.getString("ID").trim();
				PageData pdq = new PageData();
				pdq.put("ID", id);
				bookingCargoService.deleteCopeFee(pdq);
			}
		return null;
		 
	 }
	/**
	 * 查找托单处理信息
	 * @return
	 * @throws Exception
	 * @author tanwei
	 */
	@RequestMapping(value="/findConsignHandleInfo")
	public ModelAndView findConsignHandleInfo()throws Exception{
		ModelAndView view = new ModelAndView();
		view.setViewName("/business/consignhandle/consignhandle");
		return view;
		
	}
	@RequestMapping(value="consignModify")
	public ModelAndView consignModify() throws Exception{
		ModelAndView view =new ModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		String tradeType  = URLDecoder.decode(pd.getString("tradeType"), "utf-8") ;
		//String tradeType  = pd.getString("tradeType");
		String viewName ="/business/consignhandle/consignModifyWE";
		if("出口".equals(tradeType)||"其他".equals(tradeType))
		{
			viewName ="/business/consignhandle/consignModifyWE";
		}else if("进口".equals(tradeType))
		{ 
			viewName ="/business/consignhandle/consignModifyWI";
		}else{
			viewName ="/business/consignhandle/consignModifyNM";
		}
	    
		view.addObject("pd", pd);
		view.setViewName(viewName);
		return view;
	}
	/**
	 * 更新信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/updateConsignHandle")
	@ResponseBody
	public String updateConsignHandle()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		FactBookingNote bookingCargo = new FactBookingNote();
		if(!pd.getString("ID").isEmpty()){
			bookingCargo.setId(Integer.parseInt(pd.getString("ID")));
		}
		if(!pd.getString("SETTLE_COMPANY").isEmpty()){
			bookingCargo.setShipCompany(pd.getString("SETTLE_COMPANY"));
		}
		if(!pd.getString("RIVER_BOAT_NAME").isEmpty()){
			bookingCargo.setBoatName(pd.getString("RIVER_BOAT_NAME"));
		}
		if(!pd.getString("RIVER_BOAT_NAME").isEmpty()){
			bookingCargo.setBoatName(pd.getString("RIVER_BOAT_NAME"));
		}
		if(!pd.getString("BOAT_VOYAGE_NAME").isEmpty()){
			bookingCargo.setBoatVoyageName(pd.getString("BOAT_VOYAGE_NAME"));
		}
		if(!pd.getString("BOAT_PLAN_SAIL_TIME").isEmpty()){
			bookingCargo.setBoatPlanSailTime(pd.getString("BOAT_PLAN_SAIL_TIME"));
		}
		if(!pd.getString("MATCH_LOAD_REMARK").isEmpty()){
			bookingCargo.setMatchLoadRemark(pd.getString("MATCH_LOAD_REMARK"));
		}
		if(!pd.getString("CONTAINER_TYPE_NUM").isEmpty()){
			bookingCargo.setContainerTypeNum(pd.getString("CONTAINER_TYPE_NUM"));
			
		}
		if(pd.get("IS_FIO").equals("true")){
			Integer IS_FIO=1;
			bookingCargo.setIS_FIO(IS_FIO);
			
		}else{
			Integer IS_FIO=0;
			bookingCargo.setIS_FIO(IS_FIO);
		}
		if(!pd.getString("FIO_SETTLEMENT_DEPT").isEmpty()){
			bookingCargo.setFIO_SETTLEMENT_DEPT(pd.getString("FIO_SETTLEMENT_DEPT"));
			
		}
		
		bookingNoteService.updateInfo(bookingCargo);
		PageData pdq = new PageData();
		//终点港
		pdq.put("END_PORT", pd.getString("riverUnload"));
//		pdq.put("riverDelivery", pd.getString("riverDelivery"));
		//船名
		pdq.put("RIVER_BOAT_NAME", pd.getString("RIVER_BOAT_NAME"));
		//结算单位
		pdq.put("SETTLE_UNIT", pd.getString("FIO_SETTLEMENT_DEPT"));
		//海船航线名称
		pdq.put("ROUTE_NAME", pd.getString("appointShipRoute"));
		//江船航线名称拼接
		pdq.put("REMARK", pd.getString("RIVER_LOAD")+"--"+pd.getString("riverUnload"));
		//起运港
		pdq.put("START_PORT", pd.getString("RIVER_LOAD"));
		//空重箱标志
		pdq.put("EMPTY_SIGN", pd.getString("EMPTY_WEIGHT_BOX"));
		if(pd.getString("EMPTY_WEIGHT_BOX").equals("1")){
			pdq.put("EMPTY_SIGN", "重箱");
		}else if(pd.getString("EMPTY_WEIGHT_BOX").equals("0")){
			pdq.put("EMPTY_SIGN", "空箱");
		}
		//运输条款
		pdq.put("TRANSPORT_CLAUSE", pd.getString("TRANSPORT_CLAUSE"));
		//托单编号
		pdq.put("BILL_CODE", pd.getString("billCode"));
		if(!pd.getString("businessTypeId").isEmpty()){
			if(pd.getString("businessTypeId").equals("1")||pd.getString("businessTypeId").equals("2")){
				String[] BOX_TYPES = null;
				
				if(pd.getString("boxTypeConfirm").contains("&&")==true){
					 BOX_TYPES = pd.getString("boxTypeConfirm").split("&&");
					 
					 for(String a : BOX_TYPES){
						 String[] c = a.split("X");
//						 for(String b : c){
							String d= c[1];
						
						 //箱型
						 pdq.put("BOX_TYPE", d);
						 pdq.put("TRADE_TYPE", "外贸");
						//海船公司固定附加费
					PageData botaCompany = costModifyService.findBoatCompanyFixedSurcharge(pdq);
					if(botaCompany!=null){
					PageData saveBoatCompany  = new PageData();
					saveBoatCompany.put("TAX_PRICE", botaCompany.get("FEE_PRICE"));
					saveBoatCompany.put("COST_PLATE", "业务部门");
					saveBoatCompany.put("COST_NAME", "海船公司固定附加费");
					saveBoatCompany.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveBoatCompany);
					costModifyService.saveFeeCopeInfo(saveBoatCompany);
					PageData saveBoatCompanyTwo  = new PageData();
					saveBoatCompanyTwo.put("TAX_PRICE", Float.parseFloat(botaCompany.get("FEE_PRICE").toString()));
					saveBoatCompanyTwo.put("COST_PLATE", "船代板块");
					saveBoatCompanyTwo.put("COST_NAME", "海船公司固定附加费");
					saveBoatCompanyTwo.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveBoatCompanyTwo);
					costModifyService.saveFeeCopeInfo(saveBoatCompanyTwo);
					}
					//港口费用（外贸）
					
					PageData InterNalTradeFee = costModifyService.findInterNalTradeFee(pdq);
					if(InterNalTradeFee!=null){
					PageData saveInterNalTradeFee  = new PageData();
					saveInterNalTradeFee.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
					saveInterNalTradeFee.put("COST_PLATE", "业务部门");
					
					saveInterNalTradeFee.put("COST_NAME", "港口费用");
					saveInterNalTradeFee.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveInterNalTradeFee);
					costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
					PageData saveInterNalTradeFee1 = new PageData();
					saveInterNalTradeFee1.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
					saveInterNalTradeFee1.put("COST_PLATE", "船代板块");
					saveInterNalTradeFee1.put("COST_NAME", "港口费用");
					saveInterNalTradeFee1.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveInterNalTradeFee);
					costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
					}
					//CCA费用
					PageData CCAFee = costModifyService.findCCACost(pdq);
					if(CCAFee!=null){
					PageData saveCCAFee  = new PageData();
					saveCCAFee.put("TAX_PRICE", CCAFee.get("UNIT_PRICE"));
					saveCCAFee.put("COST_PLATE", "业务部门");
					saveCCAFee.put("COST_NAME", "CCA费用");
					saveCCAFee.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveCCAFee);
					costModifyService.saveFeeCopeInfo(saveCCAFee);
					PageData saveCCAFee1  = new PageData();
					saveCCAFee1.put("TAX_PRICE", CCAFee.get("UNIT_PRICE"));
					saveCCAFee1.put("COST_PLATE", "船代板块");
					saveCCAFee1.put("COST_NAME", "CCA费用");
					saveCCAFee1.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveCCAFee1);
					costModifyService.saveFeeCopeInfo(saveCCAFee1);
							}
//					 }
					 }
				}else{
					
					String[] c = pd.getString("boxTypeConfirm").split("X");
					String d= c[1];
					 pdq.put("BOX_TYPE", d);
					 pdq.put("TRADE_TYPE", "外贸");
					//海船公司固定附加费
					PageData botaCompany = costModifyService.findBoatCompanyFixedSurcharge(pdq);
					if(botaCompany!=null){
					PageData saveBoatCompany  = new PageData();
					saveBoatCompany.put("TAX_PRICE", botaCompany.get("FEE_PRICE"));
					saveBoatCompany.put("COST_PLATE", "业务部门");
					saveBoatCompany.put("COST_NAME", "海船公司固定附加费");
					saveBoatCompany.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveBoatCompany);
					costModifyService.saveFeeCopeInfo(saveBoatCompany);
					PageData saveBoatCompanyTwo  = new PageData();
					saveBoatCompanyTwo.put("TAX_PRICE", Float.parseFloat(botaCompany.get("FEE_PRICE").toString()));
					saveBoatCompanyTwo.put("COST_PLATE", "船代板块");
					saveBoatCompanyTwo.put("COST_NAME", "海船公司固定附加费");
					saveBoatCompanyTwo.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveBoatCompanyTwo);
					costModifyService.saveFeeCopeInfo(saveBoatCompanyTwo);
					}
					//港口费用（外贸）
					
					PageData InterNalTradeFee = costModifyService.findInterNalTradeFee(pdq);
					if(InterNalTradeFee!=null){
					PageData saveInterNalTradeFee  = new PageData();
					saveInterNalTradeFee.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
					saveInterNalTradeFee.put("COST_PLATE", "业务部门");
					
					saveInterNalTradeFee.put("COST_NAME", "港口费用");
					saveInterNalTradeFee.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveInterNalTradeFee);
					costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
					PageData saveInterNalTradeFee1 = new PageData();
					saveInterNalTradeFee1.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
					saveInterNalTradeFee1.put("COST_PLATE", "船代板块");
					saveInterNalTradeFee1.put("COST_NAME", "港口费用");
					saveInterNalTradeFee1.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveInterNalTradeFee);
					costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
					}
					//CCA费用
					PageData CCAFee = costModifyService.findCCACost(pdq);
					if(CCAFee!=null){
					PageData saveCCAFee  = new PageData();
					saveCCAFee.put("TAX_PRICE", CCAFee.get("UNIT_PRICE"));
					saveCCAFee.put("COST_PLATE", "业务部门");
					saveCCAFee.put("COST_NAME", "CCA费用");
					saveCCAFee.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveCCAFee);
					costModifyService.saveFeeCopeInfo(saveCCAFee);
					PageData saveCCAFee1  = new PageData();
					saveCCAFee1.put("TAX_PRICE", CCAFee.get("UNIT_PRICE"));
					saveCCAFee1.put("COST_PLATE", "船代板块");
					saveCCAFee1.put("COST_NAME", "CCA费用");
					saveCCAFee1.put("BILL_CODE", pd.getString("billCode"));
					costModifyService.saveFeeInfo(saveCCAFee1);
					costModifyService.saveFeeCopeInfo(saveCCAFee1);
							}
				}
			   
				
			}else{
				String[] BOX_TYPES = null;
				if(pd.getString("boxTypeConfirm").contains("&&")==true){
					BOX_TYPES = pd.getString("boxTypeConfirm").split("&&");
					 for(String a : BOX_TYPES){
						 String[] c = a.split("X");
//						 for(String b : c){
							String d= c[1];
						
						 //箱型
						 pdq.put("BOX_TYPE", d);
						 pdq.put("TRADE_TYPE", "内贸");
				//基础运价表
				PageData InternalTradeBase = costModifyService.findInternalTradeBase(pdq);
				if(InternalTradeBase!=null){
				PageData saveInternalTradeBase  = new PageData();
				saveInternalTradeBase.put("TAX_PRICE", InternalTradeBase.get("UNIT_PRICE"));
				saveInternalTradeBase.put("COST_PLATE", "业务部门");
				saveInternalTradeBase.put("COST_NAME", "内贸基础运价费用");
				saveInternalTradeBase.put("BILL_CODE", pd.getString("billCode"));
				costModifyService.saveFeeInfo(saveInternalTradeBase);
				costModifyService.saveFeeCopeInfo(saveInternalTradeBase);
				PageData saveInternalTradeBase1  = new PageData();
				saveInternalTradeBase1.put("TAX_PRICE", InternalTradeBase.get("UNIT_PRICE"));
				saveInternalTradeBase1.put("COST_PLATE", "船代板块");
				saveInternalTradeBase1.put("COST_NAME", "内贸基础运价费用");
				saveInternalTradeBase1.put("BILL_CODE", pd.getString("billCode"));
				costModifyService.saveFeeInfo(saveInternalTradeBase1);
				costModifyService.saveFeeCopeInfo(saveInternalTradeBase1);
				}
				//港口费用（内贸）
				pd.put("TRADE_TYPE", "内贸");
				PageData InterNalTradeFee = costModifyService.findInterNalTradeFee(pdq);
				if(InterNalTradeFee!=null){
				PageData saveInterNalTradeFee  = new PageData();
				saveInterNalTradeFee.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
				saveInterNalTradeFee.put("COST_PLATE", "业务部门");
				
				saveInterNalTradeFee.put("COST_NAME", "港口费用");
				saveInterNalTradeFee.put("BILL_CODE", pd.getString("billCode"));
				costModifyService.saveFeeInfo(saveInterNalTradeFee);
				costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
				PageData saveInterNalTradeFee1 = new PageData();
				saveInterNalTradeFee1.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
				saveInterNalTradeFee1.put("COST_PLATE", "船代板块");
				saveInterNalTradeFee1.put("COST_NAME", "港口费用");
				saveInterNalTradeFee1.put("BILL_CODE", pd.getString("billCode"));
				costModifyService.saveFeeInfo(saveInterNalTradeFee);
				costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
				}
					 }
				}else {
					String[] c = pd.getString("boxTypeConfirm").split("X");
					String d= c[1];
					 pdq.put("BOX_TYPE", d);
					 pdq.put("TRADE_TYPE", "内贸");
					//基础运价表
						PageData InternalTradeBase = costModifyService.findInternalTradeBase(pdq);
						if(InternalTradeBase!=null){
						PageData saveInternalTradeBase  = new PageData();
						saveInternalTradeBase.put("TAX_PRICE", InternalTradeBase.get("UNIT_PRICE"));
						saveInternalTradeBase.put("COST_PLATE", "业务部门");
						saveInternalTradeBase.put("COST_NAME", "内贸基础运价费用");
						saveInternalTradeBase.put("BILL_CODE", pd.getString("billCode"));
						costModifyService.saveFeeInfo(saveInternalTradeBase);
						costModifyService.saveFeeCopeInfo(saveInternalTradeBase);
						PageData saveInternalTradeBase1  = new PageData();
						saveInternalTradeBase1.put("TAX_PRICE", InternalTradeBase.get("UNIT_PRICE"));
						saveInternalTradeBase1.put("COST_PLATE", "船代板块");
						saveInternalTradeBase1.put("COST_NAME", "内贸基础运价费用");
						saveInternalTradeBase1.put("BILL_CODE", pd.getString("billCode"));
						costModifyService.saveFeeInfo(saveInternalTradeBase1);
						costModifyService.saveFeeCopeInfo(saveInternalTradeBase1);
						}
						//港口费用（内贸）
						pd.put("TRADE_TYPE", "内贸");
						PageData InterNalTradeFee = costModifyService.findInterNalTradeFee(pdq);
						if(InterNalTradeFee!=null){
						PageData saveInterNalTradeFee  = new PageData();
						saveInterNalTradeFee.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
						saveInterNalTradeFee.put("COST_PLATE", "业务部门");
						
						saveInterNalTradeFee.put("COST_NAME", "港口费用");
						saveInterNalTradeFee.put("BILL_CODE", pd.getString("billCode"));
						costModifyService.saveFeeInfo(saveInterNalTradeFee);
						costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
						PageData saveInterNalTradeFee1 = new PageData();
						saveInterNalTradeFee1.put("TAX_PRICE", InterNalTradeFee.get("UNIT_PRICE"));
						saveInterNalTradeFee1.put("COST_PLATE", "船代板块");
						saveInterNalTradeFee1.put("COST_NAME", "港口费用");
						saveInterNalTradeFee1.put("BILL_CODE", pd.getString("billCode"));
						costModifyService.saveFeeInfo(saveInterNalTradeFee);
						costModifyService.saveFeeCopeInfo(saveInterNalTradeFee);
						}
				}
			}
		}
		
		
		
		
		return null;
		
	}
	/**
	 * 修改状态
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/editState")
	@ResponseBody
	public String editState()throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		bookingCargoService.editState(pd);
		bookingCargoService.editFeeInfo(pd);
		bookingCargoService.editCostInfo(pd);
		return null;
	}
	@Override
	public List getData(String type, Map param, Page page) {
		
//		Map map = Maps.newHashMap();
//		map.put("billCode", factBookingNote.getBillCode());
//		map.put("insuranceName", factBookingNote.getInsuranceName());
//		map.put("insuranceAmount", factBookingNote.getInsuranceAmount());
//		map.put("insuranceRate", factBookingNote.getInsuranceRate());
//		map.put("insuranceRemark", factBookingNote.getInsuranceRemark());
		Map map = Maps.newHashMap();
		FactBookingNote factBookingNote = null;
		if(type.equals("insurance")){
			factBookingNote=bookingNoteService.queryByBillCode(param.get("billCode").toString());
			//托单编号
			map.put("billCode", factBookingNote.getBillCode());
			//保险名称
			map.put("insuranceName", factBookingNote.getInsuranceName());
			//保险比率
			map.put("insuranceRate", factBookingNote.getInsuranceRate());
			//保险金额
			map.put("insuranceAmount", factBookingNote.getInsuranceAmount());
			//保险备注
			map.put("insuranceRemark", factBookingNote.getInsuranceRemark());
		}else if(type.equals("customsPlan")){
			factBookingNote=bookingNoteService.queryByBillCode(param.get("billCode").toString());
			//托单编号
			map.put("billCode", factBookingNote.getBillCode());
			//提单编号
			map.put("ladingBillCode", factBookingNote.getLadingBillCode());
			//卸区
			map.put("riverUnload", factBookingNote.getRiverUnload());
			//申报地海关
			map.put("declarationCumtoms", factBookingNote.getDeclarationCumtoms());
			//船名
			map.put("BOAT_NAME",factBookingNote.getBoatName());
			//航次
			map.put("BOAT_VOYAGE_NAME", factBookingNote.getBoatVoyageName());
			//委托人
			map.put("shipperName", factBookingNote.getShipperName());
			//品名
			map.put("chineseName", factBookingNote.getChineseName());
			//箱号
			map.put("containerNo", factBookingNote.getContainerNo());
			//件数
			map.put("goodsNum", factBookingNote.getGoodsNum());
			//重量
			map.put("goodsGrossWeight", factBookingNote.getGoodsGrossWeight());
			//箱型箱量
			if(factBookingNote.getEncasementMethod()!=null && factBookingNote.getEncasementMethod()!=""){
			if(factBookingNote.getEncasementMethod().equals("0")){
				//厂装
				map.put("ENCASEMENT_METHOD", factBookingNote.getFactoryContainerTypeNum());
			}else{
				//港装
				map.put("ENCASEMENT_METHOD", factBookingNote.getPortContainerTypeNum());
			}}
			
		}else{
			factBookingNote=bookingNoteService.queryByBillCode(param.get("billCode").toString());

			PageData pd = bookingCargoService.findTrailerById(param.get("ID").toString());
			PageData tt = new PageData();
			tt.put("USERNAME", Jurisdiction.getUsername());
			PageData pd1 = null;
			try {
				pd1 = userService.findByUsername(tt);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			//托单编号
			map.put("billCode", factBookingNote.getBillCode());
			//提单编号
			map.put("ladingBillCode", factBookingNote.getLadingBillCode());
			//船名/航次
			map.put("BOAT_NAME", factBookingNote.getBoatName()+"/"+factBookingNote.getBoatVoyageName());
			//拖车运费
			map.put("TRAILER_PRICE", pd.get("TRAILER_PRICE"));
			//客户自编号
			map.put("SHIPPER_NUM",factBookingNote.getShipperNum());
			//装/拆
			if(pd.get("PACKING_TYPE").equals("1")){
				map.put("PACKING_TYPE", "拆箱");
			}else{
				map.put("PACKING_TYPE", "装箱");
			}
			//货物名称
			map.put("chineseName",factBookingNote.getChineseName());
			//目的港
			//件数
			map.put("GOODS_NUM", factBookingNote.getGoodsNum());
			//重量
			map.put("GOODS_GROSS_WEIGHT", factBookingNote.getGoodsGrossWeight());
			//体积
			map.put("VOLUME", factBookingNote.getVolume());
			//箱主
			map.put("CONTAINER_OWNER", factBookingNote.getContainerOwner());
			//箱型箱量
			if(factBookingNote.getEncasementMethod()!=null && factBookingNote.getEncasementMethod()!=""){
			if(factBookingNote.getEncasementMethod().equals("0")){
				//厂装
				map.put("ENCASEMENT_METHOD", factBookingNote.getFactoryContainerTypeNum());
			}else{
				//港装
				map.put("ENCASEMENT_METHOD", factBookingNote.getPortContainerTypeNum());
			}}
			//提箱地点
			//还箱地点
			map.put("RETCONTAINERADDR", pd.get("RETCONTAINERADDR"));
			//预计作业时间
			map.put("TRAILER_DATE", pd.get("TRAILER_DATE"));
			//作业联系人/电话
			map.put("CONTACT_PERSON", pd.get("CONTACT_PERSON")+"/"+pd.get("CONTACT_INFO"));
			//作业地点
			map.put("TRAILER_ADDR", pd.get("TRAILER_ADDR"));
			//箱号
			map.put("CONTAINER_NO", pd.get("CONTAINER_NO"));
			//备注
			map.put("REMARK", pd.get("REMARK"));
			//通知人
			map.put("NOTIFIER", Jurisdiction.getUsername());
			//EMAIL
			map.put("EMAIL", pd1.get("EMAIL"));
			//电话
			map.put("PHONE", pd1.get("PHONE"));
			//传真
			map.put("FAX",pd1.get("FAX"));
		}
		
		return Lists.newArrayList(map);
	}

	@Override
	public String getService() {
		
		return  getClass().getSimpleName();
	}

	@Override
	public Map<String, String> setNames() {
		
		
		Map m = new HashMap(3);
		//保险申报单
		m.put("insurance","insurance.xls");
		m.put("insuranceName","保险申报单("+ DateUtil.getSdfTimes()+").xls");
		m.put("insuranceModule",getService());
		//报关计划
		m.put("customsPlan", "customsPlan.xls");
		m.put("customsPlanName", "报关计划表("+ DateUtil.getSdfTimes()+").xls");
		m.put("customsPlanModule",getService());
		//托车信息
		m.put("bookNote", "bookNote.xls");
		m.put("bookNoteName", "拖车运输委托书("+ DateUtil.getSdfTimes()+").xls");
		m.put("bookNoteModule",getService());
		return m;
	}

}
